package org.absolutezero.client.presenter;

import javax.inject.Inject;

import org.absolutezero.client.events.NavigationChangeEvent;
import org.absolutezero.client.events.NavigationChangeEventHandler;
import org.absolutezero.client.view.PageContentView;
import org.absolutezero.shared.RefrigeratorRequestFactory;

import com.google.gwt.event.shared.EventBus;

public class PageContentPresenter {

	private final PageContentView pageContent;
	private final EventBus ebus;
	private final RefrigeratorRequestFactory requestFactory;
	
	@Inject
	public PageContentPresenter(PageContentView pageContent,
						EventBus ebus,
						RefrigeratorRequestFactory requestFactory) {
		
		this.ebus = ebus;
		this.pageContent = pageContent;
		this.requestFactory = requestFactory;
		
		bind();
		
	}
	
	public void setWelcomeView(){
		pageContent.setWelcomeView();
	}
	
	public void setLoginView(){
		pageContent.setLoginView();
	}
	
	public void setRegisterView(){
		pageContent.setRegisterView();
	}
	
	public void setShelvesView(){
		pageContent.setShelvesView();
	}
	
	public void setRecipesView(){
		pageContent.setRecipesView();
	}
	
	public void setRegisteredView(){
		pageContent.setRegisteredView();
	}
	
	private void bind(){
		
		ebus.addHandler(NavigationChangeEvent.TYPE, new NavigationChangeEventHandler() {
			
			@Override public void onEvent(NavigationChangeEvent e) { onNavigationChange(e);}
		});
	}
	
	private void onNavigationChange(NavigationChangeEvent e){
				
		switch(e.getNavigationItemSelected()){
		
		case SHELF_MY:
		case SHELF_BROWSE:
			pageContent.setShelvesView();
			break;
		case RECIPE_BROWSE:
		case RECIPE_MATCH:
		case RECIPE_MY:
			pageContent.setRecipesView();
			break;
		}
	}
		
}
